package application 
{
	import exey.comps.text.TextFieldLabel;
	import exey.utils.DrawUtils;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	/**
	 * Choose map and render
	 * @author Exey Panteleev
	 */
	public class MainMenu extends Sprite
	{
		[Embed(source = '../../assets/label_alternativa3d.png')] static private const LABEL_ALTERNATIVA3D_CLASS:Class;
		static public const LABEL_ALTERNATIVA3D_BITMAP_DATA:BitmapData = new LABEL_ALTERNATIVA3D_CLASS().bitmapData;
		
		[Embed(source = '../../assets/label_away3d.png')] static private const LABEL_AWAY3D_CLASS:Class;
		static public const LABEL_AWAY3D_BITMAP_DATA:BitmapData = new LABEL_AWAY3D_CLASS().bitmapData;
		
		[Embed(source = '../../assets/label_papervision3d.png')] static private const LABEL_PAPERVISION3D_CLASS:Class;
		static public const LABEL_PAPERVISION3D_BITMAP_DATA:BitmapData = new LABEL_PAPERVISION3D_CLASS().bitmapData;
		
		[Embed(source = '../../assets/label_sandy3d.png')] static private const LABEL_SANDY3D_CLASS:Class;
		static public const LABEL_SANDY3D_BITMAP_DATA:BitmapData = new LABEL_SANDY3D_CLASS().bitmapData;
		
		[Embed(source = '../../assets/map01.png')] static private const MAP_01_CLASS:Class;
		[Embed(source = '../../assets/map02.png')] static private const MAP_02_CLASS:Class;
		
		private const MAP_01:String = "data/map01.tmx";
		private const MAP_02:String = "data/map02.tmx";
		
		static public const ALTERNATIVA3D:String = "Alternativa3D";
		static public const AWAY3D:String = "Away3D";
		static public const PAPERVISION3D:String = "Papervision3D";
		static public const SANDY3D:String = "Sandy3D";
		
		private var currentRenderName:String;
		private var currentMap:String;
		
		private var map01Button:Sprite;
		private var map02Button:Sprite;
		private var alternativa3DButton:Sprite;
		private var away3DButton:Sprite;
		private var papervision3DButton:Sprite;
		private var sandy3DButton:Sprite;

		public function MainMenu() 
		{
			initialize();
			onMap02Click();
			onAlternativa3DClick();
		}
		
		private function initialize():void
		{
			var f:TextFormat = new TextFormat("Verdana", 48, 0xFFFFFF, true);
			var tf:TextField = new TextFieldLabel(this, 100, 10, f);			
			tf.text = "Map"
			
			map01Button = new Sprite();
			map01Button.addChild(new MAP_01_CLASS());
			map01Button.x = 100;
			map01Button.y = 90;
			map01Button.buttonMode = true;
			map01Button.addEventListener(MouseEvent.CLICK, onMap01Click)
			addChild(map01Button);
			
			map02Button = new Sprite();
			map02Button.addChild(new MAP_02_CLASS());
			map02Button.x = 380;
			map02Button.y = 90;
			map02Button.buttonMode = true;
			map02Button.addEventListener(MouseEvent.CLICK, onMap02Click)
			addChild(map02Button);
			
			tf = new TextFieldLabel(this, 100, 250, f);			
			tf.text = "Render Engine"
			
			alternativa3DButton = new Sprite();
			alternativa3DButton.addChild(new Bitmap(LABEL_ALTERNATIVA3D_BITMAP_DATA));
			alternativa3DButton.x = 100
			alternativa3DButton.y = 330
			alternativa3DButton.buttonMode = true;
			alternativa3DButton.addEventListener(MouseEvent.CLICK, onAlternativa3DClick);
			addChild(alternativa3DButton);
			
			away3DButton = new Sprite();
			away3DButton.addChild(new Bitmap(LABEL_AWAY3D_BITMAP_DATA));
			away3DButton.x = 200
			away3DButton.y = 330
			away3DButton.buttonMode = true;
			away3DButton.addEventListener(MouseEvent.CLICK, onAway3DClick);
			addChild(away3DButton);
			
			papervision3DButton = new Sprite();
			papervision3DButton.addChild(new Bitmap(LABEL_PAPERVISION3D_BITMAP_DATA));
			papervision3DButton.x = 300
			papervision3DButton.y = 330
			papervision3DButton.buttonMode = true;
			papervision3DButton.addEventListener(MouseEvent.CLICK, onPapervison3DClick);
			addChild(papervision3DButton);
			
			sandy3DButton = new Sprite();
			sandy3DButton.addChild(new Bitmap(LABEL_SANDY3D_BITMAP_DATA));
			sandy3DButton.x = 400
			sandy3DButton.y = 330
			sandy3DButton.buttonMode = true;
			sandy3DButton.addEventListener(MouseEvent.CLICK, onSandy3DClick);
			addChild(sandy3DButton);
			
			var playButton:Sprite = new Sprite();
			DrawUtils.drawTransparentTextButton(playButton, "PLAY", 48)
			playButton.addEventListener(MouseEvent.CLICK, onPlayClick)
			playButton.x = 400;
			playButton.y = 500;
			addChild(playButton);
		}
		
		private function onSandy3DClick(e:MouseEvent):void 
		{
			currentRenderName = SANDY3D;
			unselectAllRenderButtons();
			sandy3DButton.alpha = 1;
		}
		
		private function onPapervison3DClick(e:MouseEvent):void 
		{
			currentRenderName = PAPERVISION3D;
			unselectAllRenderButtons();
			papervision3DButton.alpha = 1;
		}
		
		private function onAway3DClick(e:MouseEvent):void 
		{
			currentRenderName = AWAY3D;
			unselectAllRenderButtons();
			away3DButton.alpha = 1;
		}
		
		private function onAlternativa3DClick(e:MouseEvent = null):void 
		{
			currentRenderName = ALTERNATIVA3D;
			unselectAllRenderButtons();
			alternativa3DButton.alpha = 1;
		}
		
		private function unselectAllRenderButtons():void 
		{
			alternativa3DButton.alpha = 0.4;
			away3DButton.alpha = 0.4;
			papervision3DButton.alpha = 0.4;
			sandy3DButton.alpha = 0.4;
		}
		
		private function onMap02Click(e:MouseEvent = null):void 
		{
			currentMap = MAP_02;
			map01Button.alpha = 0.4;
			map02Button.alpha = 1;
		}
		
		private function onMap01Click(e:MouseEvent = null):void 
		{
			currentMap = MAP_01;
			map02Button.alpha = 0.4;
			map01Button.alpha = 1;
		}
		
		private function onPlayClick(e:Event):void 
		{
			dispatchEvent(new MainMenuEvent(MainMenuEvent.PLAY_CLICK, currentRenderName, currentMap));
		}
		
		
	}
}